package com.tinycomment.restapi;

import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.tinycomment.business.ExampleBus;
/*
 *@author xiaoguang.gao@oracle.com
 *@version 2013-6-22 
 */
import com.tinycomment.model.Example;

@Path("/examples")
public class ExampleResource {
	ExampleBus bus = null;
	public ExampleResource(){
		this.bus = new ExampleBus();
	}
	
	@GET
	@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
	public Collection<Example> getAllExamples(){
		return bus.GetModelSet();
	}
	@GET
	@Path("/{id}")
	@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
	public Example getExample(@PathParam("id") int id) {
		return bus.GetModel(id);
	}
	@POST
	@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
	@Produces(MediaType.TEXT_PLAIN)
	public boolean postExample(Example example){
		return bus.Add(example);
	}
	@DELETE
	@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
	public boolean deleteExample(Example example) {
		return bus.Delete(example);
	}
}
